<?php

/**
 * pickedup actions.
 *
 * @package    www.sflast.com
 * @subpackage pickedup
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class pickedupActions extends sfActions
{
    /**
     * Executes index action
     *
     */
    public function executeIndex()
    {
        $reset_all = $this->getRequestParameter("reset_all");
        if($reset_all === "y"){
            $this->setflash("set_place", "");
            $this->setflash("hidlng", "");
            $this->setflash("hidlat", "");
            $this->setflash("hinichi", "");
            $this->setflash("type", "");
            $this->setflash("color", "");
            $this->setflash("keptin", "");
   //         $this->setflash("sonota", "");
            $this->setflash("founder_nm", "");
            $this->setflash("category", "");

        }

        ///////////////セッション問題//////////////////////////////
        $area = $this->getRequestParameter("set_place");
        //リクエストパラメータがあれば
        if($area){
            $this->setflash("set_place", $area);
            //なければ
        }else{
            $area = $this->getflash("set_place");
            $this->setflash("set_place", $area);
        }
        $this->set_place = $area;
        ////////////////////////////////////////////////////////

        $longi = $this->getRequestParameter("hidlng");
        if($longi){
            $this->setflash("hidlng", $longi);
        }else{
            $longi = $this->getflash("hidlng");
            $this->setflash("hidlng", $longi);
        }
        $this->hidlng = $longi;


        $lati = $this->getRequestParameter("hidlat");
        if($lati){
            $this->setflash("hidlat", $lati);
        }else{
            $lati = $this->getflash("hidlat");
            $this->setflash("hidlat", $lati);
        }
        $this->hidlat = $lati;

        // / / / / /  / // / / / / / / / / / /
        //echo $this->hidlat ."<br>";
        //$kekka = ($this->hidlat) * 1000000000000;
        //echo $kekka;
        //$this->kekka = $kekka;
        // / / / / / / / / / / / / / / / / / / /



        $this->year = sfConfig::get("sf_year");
        $this->month = sfConfig::get("sf_month");
        $this->days = sfConfig::get("sf_days");

        $this->search_arr = array(

      "module" => "default",
      "action" => "index",

        //"order_by" => $this->getRequestParameter("order_by", "asc"),

        //"type" => $this->getRequestParameter('type'),
        //"color" => $this->getRequestParameter('color'),
        //$this->search_place = $this->getRequestParameter('area'),
        //"area" => $this->getRequestParameter('area'),
        //areaはgooglemapsで普通に場所検索できればいいなー

      "year" => $this->getRequestParameter('year'),
      "month" => $this->getRequestParameter('month'),
      "days" => $this->getRequestParameter('days'),
      "category" => $this->getRequestParameter('category')
        );

        //実際に掲示板で使用する情報
        //$category = $this->getRequestParameter('category');
        $this->item_categorys = sfConfig::get("sf_item_categorys");
        //print_r($this->category);exit;


        //$type = $this->getRequestParameter('type');
        //$color = $this->getRequestParameter('color');
        //$area = $this->getRequestParameter('area');
        //$this->search_place = $this->getRequestParameter('area');

        //$area = $this->search_place;

        //$this->search_arr["order_by"] = "desc";

        //$b = new Criteria();
        //$b->add(FounditPeer::TYPE, $type);
        //$b->addAnd(FounditPeer::COLOR, $color);
        //$b->addAnd(FounditPeer::AREA, $area);
        ////$b = FounditPeer::setOrderByParam($search_arr["order_by"], $b);
        //$rst = FounditPeer::doSelect($b);

        //$this->rst = $rst;
        //見つかったものをＩＤごとに全部引っ張ってくる。

        ////上の検索からさらに詳細検索したい場合。（日付）



        $hinichi = $this->getRequestParameter('year')
        ."-".sprintf("%02d", $this->getRequestParameter('month'))
        ."-".sprintf("%02d", $this->getRequestParameter('days'));
        //"-".sprintf("%02d", ～)はdate関数に合わせてyyyy-mm-ddという形に直すため。
        //リクエストパラメータがあれば
        if($hinichi != "-00-00"){
            $this->setflash("hinichi", $hinichi);
            //なければ
        }else{
            $hinichi = $this->getflash("hinichi");
            $this->setflash("hinichi", $hinichi);
        }
        $this->hinichi = $hinichi;

        //    if($hinichi >= strtotime("now")){
        //        $future = "errorです";
        //        $this->future = $future
        //    }

        $category = $this->getRequestParameter('category');
        //リクエストパラメータがあれば
        if($category){
            $this->setflash("category", $category);
            //なければ
        }else{
            $category = $this->getflash("category");
            $this->setflash("category", $category);
        }
        $this->category = $category;



        $type = $this->getRequestParameter('type');
        //リクエストパラメータがあれば
        if($type){
            $this->setflash("type", $type);
            //なければ
        }else{
            $type = $this->getflash("type");
            $this->setflash("type", $type);
        }
        $this->type = $type;


        $color = $this->getRequestParameter('color');
        //リクエストパラメータがあれば
        if($color){
            $this->setflash("color", $color);
            //なければ
        }else{
            $color = $this->getflash("color");
            $this->setflash("color", $color);
        }
        $this->color = $color;

        $keptin =$this->getRequestParameter('keptin');
        //リクエストパラメータがあれば
        if($keptin){
            $this->setflash("keptin", $keptin);
            //なければ
        }else{
            $keptin = $this->getflash("keptin");
            $this->setflash("keptin", $keptin);
        }
        $this->keptin = $keptin;


  //      $sonota =$this->getRequestParameter('sonota');
        //リクエストパラメータがあれば
  //      if($sonota){
  //          $this->setflash("sonota", $sonota);
            //なければ
  //      }else{
  //          $sonota = $this->getflash("sonota");
  //          $this->setflash("sonota", $sonota);
  //      }
  //      $this->sonota = $sonota;

        $founder_nm = $this->getRequestParameter('founder_nm');
        //リクエストパラメータがあれば
        if($founder_nm){
            $this->setflash("founder_nm", $founder_nm);
            //なければ
        }else{
            $founder_nm = $this->getflash("founder_nm");
            $this->setflash("founder_nm", $founder_nm);
        }
        $this->founder_nm = $founder_nm;




        ///echo $hinichi;


        //indexpageでの、DBから検索するシステム
        /*
        $c = new Criteria();
        //ここで条件分岐する。
        if($hinichi != "-00-00"){
        //echo "まだ検索していません。";
        //}else{
        $c->add(FounditPeer::HINICHI, $hinichi, Criteria::GREATER_EQUAL);
        $found = FounditPeer::doSelect($c);
        $this->found = $found;
        }else{
        //今登録されている件数を数えたい。
        $d = new Criteria();
        $d->add(FounditPeer::ID, 1, Criteria::GREATER_EQUAL);
        $count = FounditPeer::doSelect($d);
        $cnt = count($count);
        $this->cnt = $cnt;
        //echo $cnt;
        //$this->count = $count;
        }
        */
    //URL直打ち対処
    $this->submit_check = rand();
    $this->setflash("submit_check", $this->submit_check);

        return sfView::SUCCESS;
        //$this->forward('default', 'module');
    }

    public function executeSubmit()
    {
    //Url直打ち対処
    if($this->getRequestParameter("submit_check") !=
       $this->getflash("submit_check") ||
       $this->getRequestParameter("submit_check") == "")
    {
      $this->redirect("@pickedup");
    }
    $this->setflash("submit_check", "");



        $check_hinichi = $this->getRequestParameter('check_hinichi');
        $hinichi = $this->getRequestParameter('hinichi');
        //if(isset($hinichi))
        //{
            $hinichi = $this->getflash("hinichi");
            $this->hinichi = $hinichi;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_set_place = $this->getRequestParameter('check_set_place');
        $set_place = $this->getRequestParameter('set_place');
        //if(isset($set_place))
        //{
            $set_place = $this->getflash("set_place");
            $this->set_place = $set_place;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_hidlng = $this->getRequestParameter('check_hidlng');
        $hidlng = $this->getRequestParameter('hidlng');
        //if(isset($hidlng))
        //{
            $hidlng = $this->getflash("hidlng");
            $this->hidlng = $hidlng;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_hidlat = $this->getRequestParameter('check_hidlat');
        $hidlat = $this->getRequestParameter('hidlat');
        //if(isset($hidlat))
        //{
            $hidlat = $this->getflash("hidlat");
            $this->hidlat = $hidlat;
            //$hidlat*
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_category = $this->getRequestParameter('check_category');
        $category = $this->getRequestParameter('category');
        //if(isset($type))
        //{
            $category = $this->getflash("category");
            $this->category = $category;
        //}else{
        //    $this->redirect('@pickedup');
        //}


        $check_type = $this->getRequestParameter('check_type');
        $type = $this->getRequestParameter('type');
        //if(isset($type))
        //{
            $type = $this->getflash("type");
            $this->type = $type;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_color = $this->getRequestParameter('check_color');
        $color = $this->getRequestParameter('color');
        //if(isset($color))
        //{
            $color = $this->getflash("color");
            $this->color = $color;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_keptin = $this->getRequestParameter('check_keptin');
        $keptin = $this->getRequestParameter('keptin');
        //if(isset($keptin))
        //{
            $keptin = $this->getflash("keptin");
            $this->keptin = $keptin;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        $check_founder_nm = $this->getRequestParameter('check_founder_nm');
        $founder_nm = $this->getRequestParameter('founder_nm');
        //if(isset($founder_nm))
        //{
            $founder_nm = $this->getflash("founder_nm");
            $this->founder_nm = $founder_nm;
        //}else{
        //    $this->redirect('@pickedup');
        //}

  //      $check_sonota = $this->getRequestParameter('check_sonota');
  //      $sonota = $this->getRequestParameter('sonota');
        //if(isset($sonota))
        //{
  //          $sonota = $this->getflash("sonota");
  //          $this->sonota = $sonota;
        //}else{
        //    $this->redirect('@pickedup');
        //}

        //!!!!これはtableに入れる時の処理。
        $foundit = new Foundit;
        $foundit->setHinichi($hinichi);
        $foundit->setArea($set_place);
        $foundit->setLongi($hidlng);
        $foundit->setLati($hidlat);
        $foundit->setCategory($category);
        $foundit->setType($type);
        $foundit->setColor($color);
        $foundit->setKeptin($keptin);
        $foundit->setFounderNm($founder_nm);
        //$foundit->setSonota($sonota);
        //$foundit->setCreatedAt($created_at);
        $foundit->save();
    }
    public function executeError404()
    {
        $this->redirect("/");
    }

  //バリデーションに引っかかったら動く処理

  public function handleErrorSubmit() {
      $this->request->setParameter = $this->getRequestParameter('check_set_place', $this->getRequestParameter('check_set_place'));
      $this->request->setParameter = $this->getRequestParameter('check_hinichi', $this->getRequestParameter('check_hinichi'));
      $this->request->setParameter = $this->getRequestParameter('check_hidlng', $this->getRequestParameter('check_hidlng'));
      $this->request->setParameter = $this->getRequestParameter('check_hidlat', $this->getRequestParameter('check_hidlat'));
      $this->request->setParameter = $this->getRequestParameter('check_category', $this->getRequestParameter('check_category'));
      $this->request->setParameter = $this->getRequestParameter('check_type', $this->getRequestParameter('check_type'));
      $this->request->setParameter = $this->getRequestParameter('check_color', $this->getRequestParameter('check_color'));
      $this->request->setParameter = $this->getRequestParameter('check_keptin', $this->getRequestParameter('check_keptin'));
      $this->request->setParameter = $this->getRequestParameter('check_founder_nm', $this->getRequestParameter('check_founder_nm'));
      //$this->request->setParameter = $this->getRequestParameter('check_sonota', $this->getRequestParameter('check_sonota'));

      $this->forward("pickedup", "index");
  }

}
